import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_deer/res/resources.dart';

import 'package:flutter_deer/widgets/my_app_bar.dart';

import 'package:flutter_deer/widgets/pie_chart/pie_chart.dart';
import 'package:flutter_deer/widgets/pie_chart/pie_data.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_deer/res/resources.dart';
import 'package:flutter_deer/statistics/widgets/selected_date.dart';
import 'package:flutter_deer/util/date_utils.dart' as date;
import 'package:flutter_deer/util/image_utils.dart';
import 'package:flutter_deer/util/theme_utils.dart';
import 'package:flutter_deer/widgets/bezier_chart/bezier_chart.dart';
import 'package:flutter_deer/widgets/load_image.dart';
import 'package:flutter_deer/widgets/my_app_bar.dart';
import 'package:flutter_deer/widgets/my_card.dart';
/// design/5统计/index.html#artboard11
class ExecutionProgressPage extends StatefulWidget {

  const ExecutionProgressPage({super.key});

  @override
  _ExecutionProgressPageState createState() => _ExecutionProgressPageState();
}

class _ExecutionProgressPageState extends State<ExecutionProgressPage> {

  


  @override
  Widget build(BuildContext context) {

    
    return Scaffold(
      appBar: MyAppBar(
        title: '执行进度',

        onPressed: () {

        },
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.symmetric(horizontal: 15.0),
        key: const Key('goods_statistics_list'),
        child: SafeArea(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              const Text('年度预算执行情况', style: TextStyles.textBold18),
              _buildChart(),
              const Text('月度预算执行情况', style: TextStyles.textBold18),
              _buildChart1(),
              const Text('实际执行情况', style: TextStyles.textBold18),
              const Text('实际下达指标结构', style: TextStyles.textBold18),
              _buildChart(),
              const Text('实际支出结构', style: TextStyles.textBold18),
              _buildChart(),
            ],
          ),
        ),
      ),
    );
  }
    Widget _buildChart1() {
        return AspectRatio(
      aspectRatio: 1.30,
          child: BezierChart(
            bezierChartScale: BezierChartScale.CUSTOM,
            xAxisCustomValues: const <double>[0, 5, 10, 15, 20, 25, 30],
            footerValueBuilder: (double value) => '',
            bubbleLabelValueBuilder: (double value) => '\n',
            series: [
              BezierLine(

                label: '元',
                data: _getRandomData(),
              ),
            ],
            config: BezierChartConfig(
              footerHeight: 16,
              showVerticalIndicator: false,

            ),
          ),
    );

    
  }

  List<DataPoint<dynamic>> data1 = [];


  // 数据变化图标会刷新，否则不会
  List<DataPoint<dynamic>> _getRandomData() {
    if (data1.isEmpty) {

      for (int i = 0; i < 7; i++) {
        data1.add(DataPoint<double>(value: Random.secure().nextInt(3000).toDouble(), xAxis: (i * 5).toDouble()));
      }

    }

   return data1;
  }

  Widget _buildChart() {
    return AspectRatio(
      aspectRatio: 1.30,
      // 百分比布局
      child: FractionallySizedBox(
        heightFactor: 0.8,
        child: PieChart(
          name: '执行进度',
          data: _getRandomData1(),
        ),
      ),
    );
  }

  List<PieData> data = [];


  // 数据为前十名数据与剩余数量
  List<PieData> _getRandomData1() {
    if (data.isEmpty) {
      for (int i = 0; i < 9; i++) {
        final PieData pieData = PieData();
        pieData.name = '商品$i';
        pieData.number = Random.secure().nextInt(1000);
        data.add(pieData);
      }
    }
    return data;
  }




}
